package org.example;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * 支付微服务
 *@EnableCircuitBreaker :开启Hystrix熔断功能
 */
@SpringBootApplication
@EnableCircuitBreaker
public class PayServerApplication2000
{
    public static void main( String[] args )
    {
        SpringApplication.run(PayServerApplication2000.class);
    }

    //RestTemplate :是Spring封装的一个基于Rest风格的Http客户端工具
    //@LoadBalanced:Ribbon负载均衡标签 ，让RestTemplate有负载均衡的能力
    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    //负载均衡算法 - 随机
    @Bean
    public IRule randomRule(){
        return new RandomRule();
    }
}
